<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    request.setCharacterEncoding("UTF-8");
%>
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>
    <jsp:useBean id="calculate" scope="request" class="Experiment.Add"/>
    <jsp:setProperty name="calculate" property="*"/>
    简单计算器
    <form action="FourMath.jsp" method="post">
        <p>第一个参数<input type="text" name="num1" id="num1" required="required"></p>
        <select name="symbol">
            <option value="加">+</option>
            <option value="减">-</option>
            <option value="乘">*</option>
            <option value="除">/</option>
        </select>
        <p>第二个参数<input type="text" name="num2" required="required"></p>
        <input type="submit" name="Submit" value="计算">
    </form>

        <%
    if(request.getParameter("symbol") != null){
        String symbol1=request.getParameter("symbol");
        if(symbol1.equals("除") && calculate.getNum2()==0){
            out.print("error!被除数不能为0！");
%>
        <% }
        else{
        %>
        <%="计算结果是："%>
        <%=calculate.getNum1() %>
        <%
                if(symbol1.equals("加"))
                    out.print("+");
                if(symbol1.equals("减"))
                    out.print("-");
                if(symbol1.equals("乘"))
                    out.print("*");
                if(symbol1.equals("除"))
                    out.print("/");
            %>
        <%=calculate.getNum2() %>=
        <%=calculate.getResult() %>
    <br/><%
            }
        }
    %>
</body>
</html>